#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
const int MAXN=1007;
int n,m;
bool M[MAXN][MAXN], visited[MAXN][MAXN];
char ch[MAXN];
int dirx[]={0,1,0,-1};
int diry[]={1,0,-1,0};
int res, connect;
struct node {
	int x,y;
};
inline int check(int x, int y) {
	if (M[x][y]==true && M[x+1][y]==false && M[x][y+1]==false)
		return -1;
	if (M[x][y]==true && M[x-1][y]==false && M[x][y-1]==false)
		return 1;
	return 0;
}
void BFS(node root) {
	queue<node> q;
	q.push(root);
	visited[root.x][root.y]=true;
	node nex, pre;
	int x,y;
	int cnt_s=0, cnt_e=0;
	while (!q.empty()) {
		pre=q.front(); q.pop();
		int state=check(pre.x, pre.y);
		if (state==1)  {
//			cout<<"st: "<<pre.x<<" "<<pre.y<<endl;
			++cnt_s;
		}
		if (state==-1) {
//			cout<<"en: "<<pre.x<<" "<<pre.y<<endl;
			++cnt_e;
		}
//		cout<<"haha"<<endl;
		for (int i=0; i<4; ++i) {
			x=pre.x+dirx[i];
			y=pre.y+diry[i];
			if (!visited[x][y] && M[x][y]) {
				nex.x=x; nex.y=y;
				visited[x][y]=true;
				q.push(nex);
			}
		}
	}
//	cout<<"--> "<<cnt_s<<" "<<cnt_e<<endl;
	res+=max(cnt_s, cnt_e);
	++connect;
}
int main() {
	#ifdef hai
	freopen("in.txt", "r", stdin);
	#endif
	while (~scanf("%d%d", &n, &m)) {
		for (int i=1; i<=n; ++i) {
			scanf("%s", ch);
			M[i][0]=false;
			M[i][m+1]=false;
			for (int j=1; j<=m; ++j) {
				if (ch[j-1]=='.') M[i][j]=true;
				else M[i][j]=false;
			}
		}
		for (int i=0; i<=m+1; ++i) M[0][i]=false, M[n+1][i]=false;
//		for (int i=0; i<=n+1; ++i)
//			for (int j=0; j<=m+1; ++j)
//				printf("%d%c", M[i][j], (j==m+1?'\n':' '));
		memset(visited, 0, sizeof(visited));
		node root;
		res=0; connect=0;
		for (int i=1; i<=n; ++i) {
			for (int j=1; j<=m; ++j) {
				if(M[i][j] && !visited[i][j]) root.x=i, root.y=j, BFS(root);
			}
		}
		cout<<res+(connect<=1? 0: 1)<<endl;
	}
	return 0;
}
